﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ExamSharedClasses {
    /// <summary>
    /// Exam ist die Basisklasse einer Klausur, sie enthält lediglich
    /// eindeutige Id, Klassen- und Modulzugehörigkeit, einen Namen, Erstellungs- und Schreibdatum,
    /// eine Dauer und einen Besiter.
    /// </summary>
    [Serializable()]
    public class Exam {
        public const string TABLENAME = "exam";
        public const string EXAM_ID = "exam_id";
        public const string EXAM_CLASS_ID = "exam_class_id";
        public const string EXAM_MODULE_ID = "exam_module_id";
        public const string EXAM_NAME = "exam_name";
        public const string EXAM_CREATE_DATE_TIME = "exam_create_date_time";
        public const string EXAM_WRITE_DATE_TIME = "exam_write_date_time";
        public const string EXAM_DURATION = "exam_duration";
        public const string EXAM_AUTHOR_ID = "exam_user_id";

        public int ExamId { get; set; }
        public Class ExamClass { get; set; }
        public Module ExamModule { get; set; }
        public String ExamName { get; set; }
        public DateTime ExamCreateDate { get; set; }
        public DateTime ExamWriteDate { get; set; }
        public int ExamDuration { get; set; }
        public User ExamAuthor { get; set; }

        public Exam() {
            this.ExamId = -1;
            this.ExamClass = new Class();
            this.ExamModule = new Module();
            this.ExamName = "";
            this.ExamCreateDate = new DateTime();
            this.ExamWriteDate = new DateTime();
            this.ExamDuration = -1;
            this.ExamAuthor = new User();
        }
        public Exam( int examId ) : this() {
            this.ExamId = examId;
        }
        public Exam( int examId, Class examClass, Module examModule, string examName, DateTime createDate, DateTime writeDate, int examDuration, User examAuthor ) {
            this.ExamId = examId;
            this.ExamClass = examClass;
            this.ExamModule = examModule;
            this.ExamName = examName;
            this.ExamCreateDate = createDate;
            this.ExamWriteDate = writeDate;
            this.ExamDuration = examDuration;
            this.ExamAuthor = examAuthor;
        }
        public Exam( Exam exam ) {
            this.ExamId = exam.ExamId;
            this.ExamClass = exam.ExamClass;
            this.ExamModule = exam.ExamModule;
            this.ExamName = exam.ExamName;
            this.ExamCreateDate = exam.ExamCreateDate;
            this.ExamWriteDate = exam.ExamWriteDate;
            this.ExamDuration = exam.ExamDuration;
            this.ExamAuthor = exam.ExamAuthor;
        }
        public override string ToString() {
            StringBuilder sb = new StringBuilder( "Exam: " );
            sb.Append( "ID: " + ExamId.ToString() + ", " );
            if ( ExamName != null )
                sb.Append( "Titel: " + ExamName + ", " );
            if ( ExamDuration != -1 )
                sb.Append( "Dauer (Min.): " + ( ExamDuration / 60 ).ToString() + "\n" );
            if ( ExamClass != null )
                sb.Append( "Klasse: " + ExamClass.ClassName + ", " );
            if ( ExamModule != null )
                sb.Append( "Modul: " + ExamModule.ModuleName + ", " );
            if ( ExamWriteDate != null )
                sb.Append( "Termin: " + ExamWriteDate.ToString() + "\n" );
            if ( ExamCreateDate != null )
                sb.Append( "(erstellt: " + ExamCreateDate.ToString() + ", " );            
            if ( ExamAuthor != null )
                sb.Append( "AuthorID: " + ExamAuthor.UserId.ToString() + ")\n");
            return sb.ToString();
        }
    }
}
